package com.lxx.jmb2c.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lxx.jmb2c.common.PageResult;
import com.lxx.jmb2c.common.Result;
import com.lxx.jmb2c.entity.Brand;
import com.lxx.jmb2c.service.BrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 品牌表 前端控制器
 * </p>
 *
 * @author lxx
 * @since 2025-07-10
 */
@Tag(name = "品牌管理", description = "品牌")
@RestController
@RequestMapping("/brand")
public class BrandController {

    @Resource
    private BrandService brandService;

    @Operation(summary = "新增品牌", description = "新增品牌")
    @PostMapping("")
    public Result<Object> save(@RequestBody Brand brand) {
        this.brandService.save(brand);
        return Result.success();
    }

    @Operation(summary = "查询品牌列表")
    @GetMapping("list")
    public Result<List<Brand>> list() {
        List<Brand> list = this.brandService.list();
        return Result.success(list);
    }

    @Operation(summary = "按id查询品牌")
    @GetMapping("{id}")
    public Result<Brand> get(@PathVariable("id") Long id) {
        Brand brand = this.brandService.getById(id);
        return Result.success(brand);
    }

    @Operation(summary = "分页查询品牌")
    @GetMapping("page")
    public PageResult<Brand> page(Long current, Long pageSize, String name) {
        IPage<Brand> page = this.brandService.getPage(current, pageSize, name);
        return PageResult.success(page);
    }

    @Operation(summary = "修改品牌")
    @PutMapping()
    public Result<Object> update(@RequestBody Brand brand) {
        this.brandService.updateById(brand);
        return Result.success();
    }

    @Operation(summary = "批量删除品牌")
    @DeleteMapping("")
    public Result<Object> delete(@RequestBody List<Long> ids) {
        this.brandService.deleteBatchByIds(ids);
        return Result.success();
    }

    @Operation(summary = "启用/禁用品牌")
    @PutMapping("enable/{id}")
    public Result<Object> enable(@PathVariable Long id) {
        this.brandService.enable(id);
        return Result.success();
    }
}

